<template>
  <el-dialog
    :visible.sync="visible"
    width="560px"
    :show-close="false"
    :before-close="close"
  >
    <div class="content">
      <div class="image-box">
        <img src="../../../assets/images/shuaka@2x.png" />
      </div>
      <div class="desc">请刷身份证</div>
      <div class="time">请将身份证放在识别区 ( {{time}} )</div>
    </div>
    <div class="buttons">
      <el-button class="dialog-btn outline" @click="close">取消</el-button>
    </div>
  </el-dialog>
</template>

<script type="text/ecmascript-6">
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      timer: null,
      time: 10
    }
  },
  watch: {
    visible (val) {
      if (val) {
        this.time = 10
        this.timer = setInterval(() => {
          if (this.time > 0) {
            this.time--
          } else {
            this.close()
          }
        }, 1000)
      } else {
        clearInterval(this.timer)
        this.timer = null
      }
    }
  },
  methods: {
    close () {
      clearInterval(this.timer)
      this.timer = null
      this.$emit('close')
    }
  }
}
</script>

<style lang="scss" scoped>
  .content {
    .image-box {
      margin: 50px auto 0;
      width: 162px;
      height: 102px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .desc {
      text-align: center;
      font-size: 20px;
      font-family: Microsoft YaHei UI;
      font-weight: 400;
      color: #549FF8;
      line-height: 80px;
    }
    .time {
      text-align: center;
      font-size: 14px;
      font-family: Microsoft YaHei UI;
      font-weight: 400;
      color: #999999;
    }
  }
  .buttons {
    padding-top: 50px;
    text-align: center;
    .dialog-btn {
      padding: 0;
      width: 140px;
      height: 40px;
      line-height: 38px;
      border-radius: 0;
      border: 1px solid #02579A;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #FFFFFF;
      background: #02579A;
      &.outline {
        color: #02579A;
        background: #fff;
      }
    }
  }
</style>
